#ifndef SECKEYSHM_H
#define SECKEYSHM_H

#include <QObject>
#include "seckeyinfo.h"
#include <QSharedMemory>

class SeckeyShm : public QObject
{
    Q_OBJECT
public:
    // maxnode == -1 -> 关联已经存在的共享内存
    // maxnode > 0  -> 创建共享内存
    SeckeyShm(QString key, int maxNode = -1, QObject* parent = nullptr);
    ~SeckeyShm();

    // 初始化共享内存
    void initShm();
    // 将秘钥信息写入到共享内存中
    bool writeShm(SeckeyInfo& info);
    // 将秘钥信息从共享内存中读出
    SeckeyInfo readShm(QString clientID, QString serverID);
    SeckeyInfo readShm(int keyID);

private:
    int m_maxNode;
    QSharedMemory *m_shm;
};

#endif // SECKEYSHM_H
